#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{

    int childpid;
    int i;

    //execv

    if (fork() == 0)
    {
        //child process
        char *execv_str[] = {"ls", "-a", "-l", NULL};
        if (execv("/usr/bin/ls", execv_str) < 0)
        {
            perror("error on exec");
            exit(0);
        }
    }

    else
    { //parent process
        wait(&childpid);
        printf("execv done\n");
    }

    //execl

    if (fork() == 0)
    {
        //child process
        if (execl("/usr/bin/ls", "ls", "-a", "-l", NULL) < 0)
        {
            perror("error on exec");
            exit(0);
        }
    }

    else
    { //parent process
        wait(&childpid);
        printf("execl done\n");
    }

    //execvp

    if (fork() == 0)
    {
        //child process
        char *execv_str[] = {"ls", "-a", "-l", NULL};
        if (execvp("ls", execv_str) < 0)
        {
            perror("error on exec");
            exit(0);
        }
    }

    else
    { //parent process
        wait(&childpid);
        printf("execvp done\n");
    }

    //execlp

    if (fork() == 0)
    {
        //child process
        if (execlp("ls", "ls", "-a", "-l", NULL) < 0)
        {
            perror("error on exec");
            exit(0);
        }
    }

    else
    { //parent process
        wait(&childpid);
        printf("execlp done\n");
    }

    return 0;
}